<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Account_model extends MY_Model
{
    function Account_model()
    {
        parent::MY_Model();
    }
    function ww_chk_username_available($username)
	{
		$row = $this->getRows("CALL ww_chk_username_available('$username');", false);
		$chk = $row[0] == 0 ? false : true;
		return $chk;
	}
	function ww_chk_email_available($email)
	{
		$row = $this->getRows("CALL ww_chk_email_available('$email');", false);
		$chk = $row[0] == 0 ? false : true;
		return $chk;
	}
	function ww_addnew_user($username, $password, $email, $time, $authorCode)
	{
		$this->exeQuery("CALL ww_addnew_user('$username', '$password', '$email', '$time', '$authorCode');");
	}
	function ww_get_key_code($key, $type)
	{
	   /*
        $type = 0: tim key active tai khoan.
        $type = 1: tim key reset mat khau.
       */
		return $this->getRows("CALL ww_get_key_code('$key', '$type');", 0);
	}
	function ww_update_active_and_block($uid, $value, $time)
	{
		$this->exeQuery("CALL ww_update_active_and_block('$uid', '$value', '$time');");
	}
	function ww_user_chk_password($uid, $password)
	{
		$row = $this->getRows("CALL ww_user_chk_password('$uid', '$password');", false);
		$chk = $row[0] == 0 ? false : true;
		return $chk;
	}
	function ww_request_new_password($email, $new_password, $time, $type)
	{
	   /*
        $type = 0: nhan key reset password o mail.
        $type = 1: reset password.
       */
		$this->exeQuery("CALL ww_request_new_password('$email', '$new_password', '$time', '$type');");
	}
	function ww_user_edit_account($uid, $newPassword, $time)
	{
		$this->exeQuery("CALL ww_user_edit_account('$uid', '$newPassword', '$time');");
	}
}